package com.example.wan1.view.todo;

import com.example.wan1.data.BaseObserver;
import com.example.wan1.data.RetrofitUtil;
import com.example.wan1.data.RxSchedulers;
import com.example.wan1.model.TodoBean;
import com.example.wan1.model.common.CommonResList;

import javax.inject.Inject;

/***
 * 创建时间：2020/7/31 18:20
 * 创建人：10850
 * 功能描述：
 */
public class TodoPresenter implements TodoContract.Presenter {
    @Inject
    TodoContract.View mView;

    @Inject
    public TodoPresenter() {
    }

    @Override
    public void todoList(int page, int status, int type, int orderby, int priority) {
        RetrofitUtil.getInstance().todoList(page, status, type, orderby, priority)
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<CommonResList<TodoBean>>() {
                    @Override
                    public void onSuccess(CommonResList<TodoBean> result) {
                        mView.onSuccess(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }

    public void todoListOrderAll(int page, int orderby) {
        RetrofitUtil.getInstance().todoListOrderAll(page, orderby)
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<CommonResList<TodoBean>>() {
                    @Override
                    public void onSuccess(CommonResList<TodoBean> result) {
                        mView.onSuccess(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }

    public void todoListOrder(int page, int status, int orderby) {
        RetrofitUtil.getInstance().todoListOrder(page, status, orderby)
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<CommonResList<TodoBean>>() {
                    @Override
                    public void onSuccess(CommonResList<TodoBean> result) {
                        mView.onSuccess(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }

    public void todoListAll(int page) {
        RetrofitUtil.getInstance().todoListAll(page)
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<CommonResList<TodoBean>>() {
                    @Override
                    public void onSuccess(CommonResList<TodoBean> result) {
                        mView.onSuccess(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }
}
